//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{
    public class TableStyle: IOfficeXmlSerializable
    {
        public TableStyle()
        {
            
        }
        internal TableStyle(bool isBuiltIn)
        {
            IsBuiltIn = isBuiltIn;
        }

        internal bool IsBuiltIn { get; private set; }
        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read("tableStyle"))
            {
                Name = c.GetString("name");
                Pivot = c.GetOptionalBoolean("pivot", true);
                Table = c.GetOptionalBoolean("table", true);
                while (c.ReaderLocalName == "tableStyleElement")
                    Elements.Add(c.ReadElement<TableStyleElement>());
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("tableStyle"))
            {
                c.SetString("name", Name);
                c.SetOptionalBoolean("pivot", Pivot, true);
                c.SetOptionalBoolean("table", Table, true);
                foreach (TableStyleElement e in Elements)
                    c.WriteElement(e);
            }
        }

        #endregion
        private List<TableStyleElement> elements = new List<TableStyleElement>();

        public List<TableStyleElement> Elements
        {
            get { return elements; }
           // set { elements = value; }
        }
        private TableStyleElement this[TableStyleElementType type]
        {
            get
            {
                foreach (var item in Elements)
                {
                    if (item.Type == type)
                        return item;
                }
                return null;
            }
        }
         private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private bool pivot = true;

        public bool Pivot
        {
            get { return pivot; }
            set { pivot = value; }
        }
        private bool table = true;

        public bool Table
        {
            get { return table; }
            set { table = value; }
        }

        public TableStyleElement HeaderRow
        {
            get { return this[TableStyleElementType.HeaderRow]; }
        }

        public TableStyleElement LastColumn
        {
            get { return this[TableStyleElementType.LastColumn]; }
        }

        public TableStyleElement WholeTable
        {
            get { return this[TableStyleElementType.WholeTable]; }
        }

        public TableStyleElement FirstRowStripe
        {
            get { return this[TableStyleElementType.FirstRowStripe]; }
        }

        public TableStyleElement SecondRowStripe
        {
            get { return this[TableStyleElementType.SecondRowStripe]; }
        }

        public TableStyleElement FirstColumnStripe
        {
            get { return this[TableStyleElementType.FirstColumnStripe]; }
        }

        public TableStyleElement SecondColumnStripe
        {
            get { return this[TableStyleElementType.SecondColumnStripe]; }
        }

        public TableStyleElement FirstColumn
        {
            get { return this[TableStyleElementType.FirstColumn]; }
        }

        public TableStyleElement FirstHeaderCell
        {
            get { return this[TableStyleElementType.FirstHeaderCell]; }
        }

        public TableStyleElement FirstTotalCell
        {
            get { return this[TableStyleElementType.FirstTotalCell]; }
        }

        public TableStyleElement LastHeaderCell
        {
            get { return this[TableStyleElementType.LastHeaderCell]; }
        }

        public TableStyleElement LastTotalCell
        {
            get { return this[TableStyleElementType.LastTotalCell]; }
        }

        public TableStyleElement TotalRow
        {
            get { return this[TableStyleElementType.TotalRow]; }
        }
    }
}
